///////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2009 Summit Contributors.  
// See: http://code.google.com/p/tyemill/wiki/SummitContributors
//
// The name and logo of Summit are trademarks of TYEMILL, LLC - All Rights 
// Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without 
// limitation the rights to use, copy, modify, merge, publish, distribute, 
// sublicense, and/or sell copies of the Software, and to permit persons to 
// whom the Software is furnished to do so, subject to the following 
// conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
///////////////////////////////////////////////////////////////////////////////

package summit.basecamp.wrappers
{
import summit.basecamp.constants.BasecampResource;
import summit.basecamp.helpers.CommentHelper;
import summit.data.AccountToken;
import summit.net.BasecampLoader;

/**
 * Wrapper for Basecamp comment operations.
 * 
 * @see summit.basecamp.constants.CommentableType
 */
public class CommentWrapper extends AbstractWrapper
{
	/** Constructor.
	 * 
	 * @param token 
	 * The <code>AccountToken</code> that is to be used in identifying the 
	 * Basecamp account to which API calls are made.
	 * @param loader 
	 * The <code>BasecampLoader</code> that is to be used with all requested 
	 * operations.
	 */ 
	public function CommentWrapper(token:AccountToken = null, 
	loader:BasecampLoader=null)
	{
		super(BasecampResource.COMMENT, token, loader);
	}
	
	/**
	 * Creates a new comment.
	 * 
	 * <p>Typically, the XML provided is based on the template returned from 
	 * a call to <code>prepare</code>.</p>
	 * 
	 * <p>Comments must be associated with an existing resource.
	 * The resource is required to be denoted in the XML via the 
	 * <code>commentable-id</code> and <code>commentable-type</code>.</p>
	 * 
	 * @param content Represents a comment.
	 */
	public function create(content:XML):void
	{
		loader.load(CommentHelper.create(content));
	}
	
	/**
	 * Deletes a comment.
	 * 
	 * @param id The id of the comment to be deleted.
	 */ 
	public function destroy(id:String):void
	{
		loader.load(CommentHelper.destroy(id));
	}
	
	/**
	 * Gets the editable fields of an existing comment from the store.
	 * 
	 * <p>The XML returned is pre-filled with the existing values of 
	 * the identified comment, and is ready to be resubmitted via the 
	 * <code>update</code> function.</p>
	 * 
	 * @param id The id of the comment to be retrieved.
	 */ 
	public function edit(id:String):void
	{
		loader.load(CommentHelper.edit(id));
	}
	
	/**
	 * Gets a list of comments.
	 * 
	 * <p>By default, the most recent 50 comments are returned.</p>
	 * 
	 * @param resouceId The id of a resource from which comments 
	 * are to be queried.
	 * @param commentableType The type of commentable resource 
	 * represented by the resourceId. 
	 * 
	 * @see summit.basecamp.constants.CommentableType
	 */ 
	public function list(resourceId:String, commentableType:String):void
	{
		loader.load(CommentHelper.list(resourceId, commentableType));
	}
	
	/**
	 * Retrieves a template for creating a new comment.
	 * 
	 * <p>The template retrieved is used with <code>create</code> to 
	 * submit a new comment</p>
	 * 
	 * @param resourceId The id of the resource associated 
	 * with the comment.
	 * @param commentableType The type of resource represented by 
	 * the resourceId. 
	 *
	 * @see summit.basecamp.constants.CategoryFilter
	 */ 
	public function prepare(resourceId:String, commentableType:String):void
	{
		loader.load(CommentHelper.prepare(resourceId, commentableType));	
	}
	
	/**
	 * Gets a single comment.
	 * 
	 * @param id The id of the comment to be read.
	 */
	public function read(id:String):void
	{
		loader.load(CommentHelper.read(id));
	}
	
	/**
	 * Updates an existing comment.
	 * 
	 * <p><code>content</code> submitted to <code>update</code> is typically
	 * retrieved from <code>edit</code>.</p>
	 * 
	 * @param content The updated XML content of an existing comment.
	 */ 
	public function update(content:XML):void
	{
		loader.load(CommentHelper.update(content));	
	}
	
}
}
//////////////////////////////////////////////////////// gmarius@tyemill.com //